//
//  Utility.m
//  MandarinDucks
//
//  Created by 艾特—iOS on 5/12/16.
//  Copyright © 2016年 艾特_iOS. All rights reserved.
//

#import "Utility.h"

@implementation Utility

@end



#pragma mark -
#pragma mark NSObject(addmethods)

@implementation NSObject(addmethods)

- (NSMutableAttributedString *)string:(NSString *)str andFirst:(NSInteger)num1 andSecond:(NSInteger)num2 with:(UIColor *)color
{
    NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:str];
    [attriStr addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(num1, num2)];
    return attriStr;
}

//UIColor转UIImage。
- (UIImage *)createImageWithColor:(UIColor *) color
{
    CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

// 时间戳转时间
- (NSString *)timeStrIntervalSince:(NSString *)timeStamp withModel:(NSString *)dateStr
{
    NSString *str = timeStamp;
    NSTimeInterval time = [str doubleValue];
    NSDate *detaleDate = [NSDate dateWithTimeIntervalSince1970:time];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:dateStr];
    
    return [dateFormatter stringFromDate:detaleDate];
}

- (UIImageView *)imgviewOne:(CGRect)rect and:(NSString *)imgUrlStr and:(NSString *)neme and:(NSString *)monloge withStyle:(NSString *)style
{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:rect];
    
    CGFloat backWid = rect.size.width;
    CGFloat backHei = rect.size.height;
    float scrole = backWid / 640;
    
    // 唯美
    if ([style isEqualToString:@"beautiful"]) {
        backImgView.image = IMG(@"beautiful1.jpg");
        
        UIImageView *avatore = [[UIImageView alloc] initWithFrame:CGRectMake(195 * scrole, 245 *scrole, 250 *scrole, 250 * scrole)];
        avatore.layer.masksToBounds = YES;
        avatore.layer.cornerRadius = 125 * scrole;
        avatore.layer.borderWidth = 2.0f;
        avatore.layer.borderColor = [UIColor whiteColor].CGColor;
        if ([imgUrlStr length] != 0) {
            [avatore sd_setImageWithURL:[NSURL URLWithString:imgUrlStr] placeholderImage:IMG(@"nopicture")];
        }
        [backImgView addSubview:avatore];
        
        for (int i = 0; i < 2; i++) {
            UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, avatore.frame.origin.y + avatore.frame.size.height + 10 * scrole + (i % 2) * 20, backWid - 20, 20)];
            title.backgroundColor = [UIColor clearColor];
            title.textAlignment = NSTextAlignmentCenter;
            if (backWid < 320) {
                title.font = [UIFont systemFontOfSize:13];
            }
            else {
                title.font = [UIFont systemFontOfSize:18];
            }
            if (i == 0) {
                title.textColor = [UIColor blackColor];
                title.text = @"hello!";
            }
            else {
                title.textColor = BaseColor;
                NSString *nameStr = [NSString stringWithFormat:@"我是%@", neme];
                title.attributedText = [self string:nameStr andFirst:0 andSecond:2 with:[UIColor blackColor]];
            }
            [backImgView addSubview:title];
        }
        
        UIImageView *heartImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 735 * scrole, 40 * scrole, 40 *scrole)];
        heartImg.image = IMG(@"bea_heart");
        [backImgView addSubview:heartImg];
        
        UILabel *molo = [[UILabel alloc] initWithFrame:CGRectMake(heartImg.frame.origin.x + heartImg.frame.size.width + 5, heartImg.frame.origin.y, 150, 40 *scrole)];
        molo.textColor = BaseColor;
        if (backWid < 320) {
            molo.font = [UIFont systemFontOfSize:13];
        }
        else {
            molo.font = [UIFont systemFontOfSize:18];
        }
        molo.text = @"内心独白";
        [backImgView addSubview:molo];
        
        UIFont *font;
        if (backWid < 320) {
            font = [UIFont systemFontOfSize:12];
        }
        else {
            font = [UIFont systemFontOfSize:17];
        }
        
        CGRect rect = [monloge boundingRectWithSize:CGSizeMake(backWid - 20, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
        
        CGFloat infoHei = 0;
        if (molo.frame.origin.y + molo.frame.size.height + 5 + rect.size.height > backHei - 180 * scrole) {
            infoHei = backHei - 180 * scrole - (molo.frame.origin.y + molo.frame.size.height + 5);
        }
        else {
            infoHei = rect.size.height;
        }
        
        UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(10, molo.frame.origin.y + molo.frame.size.height + 5, backWid - 20, infoHei)];
        infoLa.textColor = COLOR(11, 7, 32,1);
        infoLa.font = font;
        infoLa.text = monloge;
        infoLa.numberOfLines = 0;
        [backImgView addSubview:infoLa];
    }
    
    // 杂志
    if ([style isEqualToString:@"magazine"]) {
        backImgView.image = IMG(@"magazine1.jpg");
        
        UIImageView *avator = [[UIImageView alloc] initWithFrame:CGRectMake(backWid - 35 * scrole - 250 * scrole, 160 * scrole, 250 * scrole, 250 * scrole)];
        avator.layer.masksToBounds = YES;
        avator.layer.cornerRadius = 125 * scrole;
        avator.layer.borderWidth = 2.0f;
        avator.layer.borderColor = [UIColor whiteColor].CGColor;
        if ([imgUrlStr length] != 0) {
            [avator sd_setImageWithURL:[NSURL URLWithString:imgUrlStr] placeholderImage:IMG(@"nopicture")];
        }
        [backImgView addSubview:avator];
        
        UILabel *nameLa = [[UILabel alloc] initWithFrame:CGRectMake(10, 500 * scrole, backWid - 10 - 35 *scrole - 5, 20)];
        nameLa.backgroundColor = [UIColor clearColor];
        nameLa.textColor = [UIColor whiteColor];
        nameLa.text = [NSString stringWithFormat:@"%@", neme];
        nameLa.textAlignment = NSTextAlignmentRight;
        if (backWid < 320) {
            nameLa.font = [UIFont systemFontOfSize:13];
        }
        else {
            nameLa.font = [UIFont systemFontOfSize:18];
        }
        [backImgView addSubview:nameLa];
        
        UILabel *monoLa = [[UILabel alloc] initWithFrame:CGRectMake(52 * scrole, 775 * scrole, backWid - 52 * scrole * 2, 200 * scrole)];
        monoLa.textColor = [UIColor whiteColor];
        monoLa.backgroundColor = [UIColor clearColor];
        if (backWid < 320) {
            monoLa.font = FONT(12);
        }
        else {
            monoLa.font = FONT(16);
        }
        monoLa.text = monloge;
        monoLa.numberOfLines = 0;
        [backImgView addSubview:monoLa];
    }
    
    // 深紫色
    if ([style isEqualToString:@"purple"]) {
        backImgView.image = IMG(@"purple1.jpg");
        
        UILabel *titleLa = [[UILabel alloc] initWithFrame:CGRectMake(10, 225 * scrole, backWid - 20, 20)];
        titleLa.backgroundColor = [UIColor clearColor];
        titleLa.textColor = [UIColor whiteColor];
        titleLa.textAlignment = NSTextAlignmentCenter;
        if (backWid < 320) {
            titleLa.font = FONT(13);
        }
        else {
            titleLa.font = FONT(18);
        }
        titleLa.text = [NSString stringWithFormat:@"我是%@", neme];
        [backImgView addSubview:titleLa];
        
        UIImageView *avator = [[UIImageView alloc] initWithFrame:CGRectMake(195 * scrole, titleLa.frame.origin.y + titleLa.frame.size.height + 20 * scrole, 250 * scrole, 250 *scrole)];
        avator.backgroundColor = [UIColor clearColor];
        avator.layer.masksToBounds = YES;
        avator.layer.cornerRadius = 125 * scrole;
        avator.layer.borderWidth = 2.0f;
        avator.layer.borderColor = [UIColor whiteColor].CGColor;
        if ([imgUrlStr length] != 0) {
            [avator sd_setImageWithURL:[NSURL URLWithString:imgUrlStr] placeholderImage:IMG(@"nopicture")];
        }
        [backImgView addSubview:avator];
        
        CGFloat firstHei = 660 * scrole;
        
        UIFont *font;
        if (backWid < 320) {
            font = FONT(12);
        }
        else {
            font = FONT(17);
        }
        
        CGRect rect = [monloge boundingRectWithSize:CGSizeMake(backWid - 30, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
        
        CGFloat infoHei = 0;
        if (firstHei + 25 + rect.size.height > backHei - 150 * scrole) {
            infoHei = backHei - 150 * scrole - (firstHei + 25);
        }
        else {
            infoHei = rect.size.height;
        }
        
        UIView *monoView = [[UIView alloc] initWithFrame:CGRectMake(10, firstHei, backWid - 20, 25 + infoHei + 15)];
        monoView.backgroundColor = [UIColor blackColor];
        [backImgView addSubview:monoView];
        
        UILabel *monoTitle = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, monoView.frame.size.width - 10, 20)];
        monoTitle.backgroundColor = [UIColor clearColor];
        monoTitle.textColor = [UIColor whiteColor];
        if (backWid < 320) {
            monoTitle.font = FONT(13);
        }
        else {
            monoTitle.font = FONT(18);
        }
        monoTitle.text = @"内心独白:";
        [monoView addSubview:monoTitle];
        
        UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(5, monoTitle.frame.origin.y + monoTitle.frame.size.height + 5, monoView.frame.size.width - 10, infoHei)];
        infoLa.textColor = COLOR(249, 232, 134,1);
        infoLa.font = font;
        infoLa.text = monloge;
        infoLa.numberOfLines = 0;
        [monoView addSubview:infoLa];
    }
    
    return backImgView;
}

- (UIImageView *)imageViewTwo:(CGRect)rect andInfoDic:(NSDictionary *)dict withType:(NSString *)type
{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:rect];
    
    CGFloat backWid = rect.size.width;
    float scrole = backWid / 640;
    
    if ([type isEqualToString:@"beautiful"]) {
        backImgView.image = IMG(@"beautiful2.jpg");
        
        for (int i = 0; i < 7; i++) {
            UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
            title.backgroundColor = BaseColor;
            title.textColor = [UIColor whiteColor];
            title.font = FONT(16);
            title.textAlignment = NSTextAlignmentCenter;
            title.layer.masksToBounds = YES;
            title.layer.cornerRadius = 10.0f;
            if (i == 0) {
                if ([dict objectForKey:@"marital_status"]) {
                    title.text = [NSString stringWithFormat:@" %@   ", [dict objectForKey:@"marital_status"]];
                }
            }
            else if (i == 1) {
                if ([dict objectForKey:@"member_age"]) {
                    title.text = [NSString stringWithFormat:@" %@岁   ", [dict objectForKey:@"member_age"]];
                }
            }
            else if (i == 2) {
                if ([dict objectForKey:@"height"]) {
                    title.text = [NSString stringWithFormat:@" %@CM   ", [dict objectForKey:@"height"]];
                }
            }
            else if (i == 3) {
                if ([dict objectForKey:@"xingzuo"]) {
                    title.text = [NSString stringWithFormat:@" %@   ", [dict objectForKey:@"xingzuo"]];
                }
            }
            else if (i == 4) {
                if ([dict objectForKey:@"school_age"]) {
                    title.text = [NSString stringWithFormat:@" %@   ", [dict objectForKey:@"school_age"]];
                }
            }
            else if (i == 5) {
                if ([dict objectForKey:@"native_place_name"]) {
                    title.text = [NSString stringWithFormat:@" %@   ", [dict objectForKey:@"native_place_name"]];
                }
            }
            else {
                if ([dict objectForKey:@"month_income"]) {
                    title.text = [NSString stringWithFormat:@" %@   ", [dict objectForKey:@"month_income"]];
                }
            }
            [title sizeToFit];
            [backImgView addSubview:title];
            
            CGRect rect = title.frame;
            CGFloat titWid = rect.size.width;
            if (i == 0) {
                title.frame = CGRectMake(205 * scrole - titWid / 2, 190 * scrole, titWid, 20);
            }
            else if (i == 1) {
                title.frame = CGRectMake(backWid - (205 * scrole + titWid / 2), 190 * scrole, titWid, 20);
            }
            else if (i == 2) {
                title.frame = CGRectMake(120 * scrole - titWid / 2, 410 * scrole, titWid, 20);
            }
            else if (i == 3) {
                title.frame = CGRectMake(backWid - (120 * scrole + titWid / 2), 410 * scrole, titWid, 20);
            }
            else if (i == 4) {
                title.frame = CGRectMake(175 * scrole - titWid / 2, 560 * scrole, titWid, 20);
            }
            else if (i == 5) {
                title.frame = CGRectMake(backWid - (175 * scrole + titWid / 2), 560 * scrole, titWid, 20);
            }
            else {
                title.frame = CGRectMake(backWid / 2 - titWid / 2, 675 * scrole, titWid, 20);
            }
        }
    }
    else if ([type isEqualToString:@"magazine"]) {
        backImgView.image = IMG(@"magazine2.jpg");
        
        for (int i = 0; i < 3; i++) {
            UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(40 * scrole, 800 * scrole + (i % 3) *25, backWid - 40 * scrole * 2, 25)];
            title.backgroundColor = [UIColor clearColor];
            title.textColor = [UIColor whiteColor];
            title.font = FONT(16);
            title.textAlignment = NSTextAlignmentRight;
            if (i == 0) {
                title.text = [NSString stringWithFormat:@"%@  %@  %@", [NSString stringWithFormat:@"%@", [dict objectForKey:@"marital_status"]], [NSString stringWithFormat:@"%@", [dict objectForKey:@"school_age"]], [NSString stringWithFormat:@"%@", [dict objectForKey:@"month_income"]]];
            }
            else if (i == 1) {
                title.text = [NSString stringWithFormat:@"%@CM  %@", [NSString stringWithFormat:@"%@", [dict objectForKey:@"height"]], [NSString stringWithFormat:@"%@", [dict objectForKey:@"native_place_name"]]];
            }
            else {
                title.text = [NSString stringWithFormat:@"%@岁  %@", [NSString stringWithFormat:@"%@", [dict objectForKey:@"member_age"]], [NSString stringWithFormat:@"%@", [dict objectForKey:@"xingzuo"]]];
            }
            [backImgView addSubview:title];
        }
    }
    else if ([type isEqualToString:@"purple"]) {
        backImgView.image = IMG(@"purple2.jpg");
        
        for (int i = 0; i < 7; i++) {
            UILabel *title = [[UILabel alloc] init];
            title.backgroundColor = [UIColor clearColor];
            title.font = FONT(15);
            title.textAlignment = NSTextAlignmentCenter;
            title.textColor = COLOR(249, 232, 134,1);
            if (i == 0) {
                title.frame = CGRectMake(207 * scrole - 50, 362 * scrole - 25, 100, 20);
                if ([dict objectForKey:@"marital_status"]) {
                    title.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"marital_status"]];
                }
            }
            else if (i == 1) {
                title.frame = CGRectMake(445 * scrole - 50, 362 * scrole - 25, 100, 20);
                if ([dict objectForKey:@"member_age"]) {
                    title.text = [NSString stringWithFormat:@"%@岁", [dict objectForKey:@"member_age"]];
                }
            }
            else if (i == 2) {
                title.frame = CGRectMake(81 * scrole, 560 * scrole - 10, 100, 20);
                title.textAlignment = NSTextAlignmentLeft;
                if ([dict objectForKey:@"height"]) {
                    title.text = [NSString stringWithFormat:@"%@CM", [dict objectForKey:@"height"]];
                }
            }
            else if (i == 3) {
                title.frame = CGRectMake(573 * scrole - 70, 560 * scrole - 10, 70, 20);
                if ([dict objectForKey:@"xingzuo"]) {
                    title.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"xingzuo"]];
                }
            }
            else if (i == 4) {
                title.frame = CGRectMake(151 * scrole - (backWid / 2 - 20) / 2, 684 * scrole + 10, backWid / 2 - 20, 20);
                if ([dict objectForKey:@"school_age"]) {
                    title.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"school_age"]];
                }
            }
            else if (i == 5) {
                title.frame = CGRectMake(487 * scrole - (backWid / 2 - 20) / 2, 684 * scrole + 10, backWid / 2 - 20, 20);
                if ([dict objectForKey:@"native_place_name"]) {
                    title.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"native_place_name"]];
                }
            }
            else {
                title.frame = CGRectMake(317 * scrole - 100, 817 * scrole + 10, 200, 20);
                if ([dict objectForKey:@"month_income"]) {
                    title.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"month_income"]];
                }
            }
            [backImgView addSubview:title];
        }
    }
    
    return backImgView;
}

- (UIImageView *)imageViewThree:(CGRect)rect andInfoDic:(NSDictionary *)dict withType:(NSString *)type
{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:rect];
    
    CGFloat backWid = rect.size.width;
    float scrole = backWid / 640;
    
    if ([type isEqualToString:@"beautiful"]) {
        backImgView.image = IMG(@"beautiful3.jpg");
        
        CGFloat imgWid = 225 * scrole;
        CGFloat forMari = 70 * scrole;
        NSArray *imgArr;
        if ([dict objectForKey:@"new_file_name"]) {
            imgArr = [dict objectForKey:@"new_file_name"];
        }
        
        for (int i = 0; i < 6; i++) {
            UIImageView *iconImg = [[UIImageView alloc] init];
            iconImg.backgroundColor = [UIColor clearColor];
            iconImg.layer.masksToBounds = YES;
            iconImg.layer.cornerRadius = imgWid / 2;
            iconImg.layer.borderWidth = 1.0f;
            iconImg.layer.borderColor = [UIColor whiteColor].CGColor;
            if (i < imgArr.count) {
                [iconImg sd_setImageWithURL:[NSURL URLWithString:[imgArr objectAtIndex:i]]];
            }
            if (i == 0) {
                iconImg.frame = CGRectMake(forMari, 205 * scrole, imgWid, imgWid);
            }
            else if (i == 1) {
                iconImg.frame = CGRectMake(backWid - forMari - imgWid, 205 * scrole, imgWid, imgWid);
            }
            else if (i == 2) {
                iconImg.frame = CGRectMake(forMari, 610 * scrole, imgWid, imgWid);
            }
            else if (i == 3) {
                iconImg.frame = CGRectMake(backWid - forMari - imgWid, 610 * scrole, imgWid, imgWid);
            }
            else if (i == 4) {
                iconImg.frame = CGRectMake(forMari, 875 * scrole, imgWid, imgWid);
            }
            else {
                iconImg.frame = CGRectMake(backWid - forMari - imgWid, 875 * scrole, imgWid, imgWid);
            }
            [backImgView addSubview:iconImg];
        }
    }
    else if ([type isEqualToString:@"magazine"]) {
        backImgView.image = IMG(@"magazine3.jpg");
        
        NSArray *imgArr;
        if ([dict objectForKey:@"new_file_name"]) {
            imgArr = [dict objectForKey:@"new_file_name"];
        }
        
        for (int i = 0; i < 4; i++) {
            UIImageView *iconImg = [[UIImageView alloc] init];
            iconImg.backgroundColor = [UIColor clearColor];
            iconImg.layer.masksToBounds = YES;
            iconImg.layer.borderWidth = 2.0f;
            iconImg.layer.borderColor = [UIColor whiteColor].CGColor;
            if (i == 0) {
                iconImg.frame = CGRectMake(18 * scrole, 50 * scrole, 290 * scrole, 290 * scrole);
            }
            else if (i == 1) {
                iconImg.frame = CGRectMake(223 * scrole, 191 * scrole, 400 * scrole, 400 * scrole);
            }
            else if (i == 2) {
                iconImg.frame = CGRectMake(18 * scrole, 364 * scrole, 272 * scrole, 272 * scrole);
            }
            else {
                iconImg.frame = CGRectMake(9 * scrole, 619 * scrole, 230 * scrole, 230 * scrole);
            }
            if (i < imgArr.count) {
                [iconImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [imgArr objectAtIndex:i]]]];
            }
            [backImgView addSubview:iconImg];
        }
    }
    else if ([type isEqualToString:@"purple"]) {
        backImgView.image = IMG(@"purple3.jpg");
        
        NSArray *imgArr;
        if ([dict objectForKey:@"new_file_name"]) {
            imgArr = [dict objectForKey:@"new_file_name"];
        }
        
        for (int i = 0; i < 3; i++) {
            UIImageView *iconImg = [[UIImageView alloc] init];
            iconImg.backgroundColor = [UIColor clearColor];
            iconImg.layer.masksToBounds = YES;
            iconImg.layer.borderWidth = 2.0f;
            iconImg.layer.borderColor = [UIColor whiteColor].CGColor;
            if ( i == 0) {
                iconImg.frame = CGRectMake(21 * scrole, 244 * scrole, 405 * scrole, 405 *scrole);
            }
            else if (i == 1) {
                iconImg.frame = CGRectMake(346 * scrole, 394 * scrole, 285 * scrole, 285 *scrole);
            }
            else {
                iconImg.frame = CGRectMake(108 * scrole, 613 * scrole, 318 * scrole, 318 *scrole);
            }
            if (i < imgArr.count) {
                [iconImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [imgArr objectAtIndex:i]]]];
            }
            [backImgView addSubview:iconImg];
        }
    }
    
    return backImgView;
}

- (UIImageView *)imageViewFour:(CGRect)rect andInfoDic:(NSDictionary *)dict withType:(NSString *)type
{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:rect];
    
    CGFloat backWid = rect.size.width;
    float scrole = backWid / 640;
    
    if ([type isEqualToString:@"beautiful"]) {
        backImgView.image = IMG(@"beautiful4.jpg");
        
        CGFloat imgWid = 580 * scrole;
        CGFloat forMari = 30 * scrole;
        NSString *imgStr;
        if ([dict objectForKey:@"new_file_name"]) {
            NSArray *imgArr = [dict objectForKey:@"new_file_name"];
            if (imgArr.count > 7) {
                imgStr = [imgArr objectAtIndex:6];
            }
        }
        
        UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(forMari, 425 * scrole, imgWid, imgWid)];
        if ([imgStr length] != 0) {
            [iconImg sd_setImageWithURL:[NSURL URLWithString:imgStr]];
        }
        iconImg.layer.masksToBounds = YES;
        iconImg.layer.cornerRadius = imgWid / 2;
        iconImg.layer.borderWidth = 2.0f;
        iconImg.layer.borderColor = [UIColor whiteColor].CGColor;
        [backImgView addSubview:iconImg];
    }
    else if ([type isEqualToString:@"magazine"]) {
        backImgView.image = IMG(@"magazine4.jpg");
        
        NSString *imgStr;
        if ([dict objectForKey:@"new_file_name"]) {
            NSArray *imgArr = [dict objectForKey:@"new_file_name"];
            if (imgArr.count >= 5) {
                imgStr = [imgArr objectAtIndex:4];
            }
        }
        
        UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 160 * scrole, backWid, backWid)];
        iconImg.backgroundColor = [UIColor clearColor];
        iconImg.layer.masksToBounds = YES;
        iconImg.layer.borderWidth = 1.0f;
        iconImg.layer.borderColor = [UIColor blackColor].CGColor;
        if ([imgStr length] != 0) {
            [iconImg sd_setImageWithURL:[NSURL URLWithString:imgStr]];
        }
        [backImgView addSubview:iconImg];
    }
    else if ([type isEqualToString:@"purple"]) {
        backImgView.image = IMG(@"purple4.jpg");
        
        NSString *imgStr;
        if ([dict objectForKey:@"new_file_name"]) {
            NSArray *imgArr = [dict objectForKey:@"new_file_name"];
            if (imgArr.count >= 5) {
                imgStr = [imgArr objectAtIndex:3];
            }
        }
        
        UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(12 * scrole, 319 * scrole, 616 * scrole, 616 * scrole)];
        iconImg.backgroundColor = [UIColor clearColor];
        iconImg.layer.masksToBounds = YES;
        iconImg.layer.cornerRadius = 308 * scrole;
        if ([imgStr length] != 0) {
            [iconImg sd_setImageWithURL:[NSURL URLWithString:imgStr]];
        }
        [backImgView addSubview:iconImg];
    }
    
    return backImgView;
}

- (UIImageView *)imageViewFive:(CGRect)rect andInfoDic:(NSDictionary *)dict withType:(NSString *)type
{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:rect];
    
    CGFloat backWid = rect.size.width;
    float scrole = backWid / 640;
    
    if ([type isEqualToString:@"beautiful"]) {
        backImgView.image = IMG(@"beautiful5.jpg");
        
        CGFloat imgWid = 580 * scrole;
        CGFloat forMari = 30 * scrole;
        NSString *imgStr;
        if ([dict objectForKey:@"new_file_name"]) {
            NSArray *imgArr = [dict objectForKey:@"new_file_name"];
            if (imgArr.count == 8) {
                imgStr = [imgArr objectAtIndex:7];
            }
        }
        
        UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(forMari, 425 * scrole, imgWid, imgWid)];
        if ([imgStr length] != 0) {
            [iconImg sd_setImageWithURL:[NSURL URLWithString:imgStr]];
        }
        iconImg.layer.masksToBounds = YES;
        iconImg.layer.cornerRadius = imgWid / 2;
        iconImg.layer.borderWidth = 2.0f;
        iconImg.layer.borderColor = [UIColor whiteColor].CGColor;
        [backImgView addSubview:iconImg];
    }
    else if ([type isEqualToString:@"magazine"]) {
        backImgView.image = IMG(@"magazine5.jpg");
        
        NSString *imgStr;
        if ([dict objectForKey:@"new_file_name"]) {
            NSArray *imgArr = [dict objectForKey:@"new_file_name"];
            if (imgArr.count >= 5) {
                imgStr = [imgArr objectAtIndex:5];
            }
        }
        
        UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 160 * scrole, backWid, backWid)];
        iconImg.backgroundColor = [UIColor clearColor];
        iconImg.layer.masksToBounds = YES;
        iconImg.layer.borderWidth = 1.0f;
        iconImg.layer.borderColor = [UIColor blackColor].CGColor;
        if ([imgStr length] != 0) {
            [iconImg sd_setImageWithURL:[NSURL URLWithString:imgStr]];
        }
        [backImgView addSubview:iconImg];
    }
    else if ([type isEqualToString:@"purple"]) {
        backImgView.image = IMG(@"purple5.jpg");
        
        NSString *imgStr;
        if ([dict objectForKey:@"new_file_name"]) {
            NSArray *imgArr = [dict objectForKey:@"new_file_name"];
            if (imgArr.count >= 5) {
                imgStr = [imgArr objectAtIndex:4];
            }
        }
        
        UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(12 * scrole, 319 * scrole, 616 * scrole, 616 * scrole)];
        iconImg.backgroundColor = [UIColor clearColor];
        iconImg.layer.masksToBounds = YES;
        iconImg.layer.cornerRadius = 308 * scrole;
        if ([imgStr length] != 0) {
            [iconImg sd_setImageWithURL:[NSURL URLWithString:imgStr]];
        }
        [backImgView addSubview:iconImg];
    }
    
    return backImgView;
}

- (UIImageView *)imageViewSix:(CGRect)rect andInfoDic:(NSDictionary *)dict withType:(NSString *)type
{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:rect];
    
    CGFloat backWid = rect.size.width;
    float scrole = backWid / 640;
    
    if ([type isEqualToString:@"beautiful"]) {
        backImgView.image = IMG(@"beautiful6.jpg");
        
        for (int i = 0; i < 8; i++) {
            UILabel *title = [[UILabel alloc] init];
            title.backgroundColor = [UIColor clearColor];
            title.font = FONT(14);
            title.textColor = COLOR(115, 114, 112,1);
            title.textAlignment = NSTextAlignmentCenter;
            title.layer.masksToBounds = YES;
            title.layer.cornerRadius = 5.0f;
            title.layer.borderWidth = 1.0f;
            title.layer.borderColor = COLOR(115, 114, 112,1).CGColor;
            if (i == 0) {
                title.text = @"年龄";
                title.frame = CGRectMake(240 * scrole, 170 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(10, title.frame.origin.y, title.frame.origin.x - 15, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentRight;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_age"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@岁", [dict objectForKey:@"spouse_age"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 1) {
                title.text = @"身高";
                title.frame = CGRectMake(backWid - 240 * scrole - 70 * scrole, 170 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x + title.frame.size.width + 5, title.frame.origin.y, backWid - (title.frame.origin.x + title.frame.size.width + 5) - 10, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentLeft;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_height"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@CM", [dict objectForKey:@"spouse_height"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 2) {
                title.text = @"婚姻状况";
                title.frame = CGRectMake(240 * scrole, 275 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(10, title.frame.origin.y, title.frame.origin.x - 15, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentRight;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_marital_status"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_marital_status"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 3) {
                title.text = @"居住地址";
                title.frame = CGRectMake(backWid - 240 * scrole - 70 * scrole, 275 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x + title.frame.size.width + 5, title.frame.origin.y, backWid - (title.frame.origin.x + title.frame.size.width + 5) - 10, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentLeft;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_area_in"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_area_in"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 4) {
                title.text = @"月收入";
                title.frame = CGRectMake(240 * scrole, 560 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(10, title.frame.origin.y, title.frame.origin.x - 15, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentRight;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_month_income"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_month_income"]];
                }
                ageLa.numberOfLines = 2;
                [backImgView addSubview:ageLa];
            }
            else if (i == 5) {
                title.text = @"学历";
                title.frame = CGRectMake(backWid - 240 * scrole - 70 * scrole, 560 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x + title.frame.size.width + 5, title.frame.origin.y, backWid - (title.frame.origin.x + title.frame.size.width + 5) - 10, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentLeft;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_school_age"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_school_age"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 6) {
                title.text = @"子女状况";
                title.frame = CGRectMake(240 * scrole, 667 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(10, title.frame.origin.y, title.frame.origin.x - 15, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentRight;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_childs"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_childs"]];
                }
                [backImgView addSubview:ageLa];
            }
            else {
                title.text = @"购房情况";
                title.frame = CGRectMake(backWid - 240 * scrole - 70 * scrole, 667 * scrole, 70 * scrole, 70 * scrole);
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x + title.frame.size.width + 5, title.frame.origin.y, backWid - (title.frame.origin.x + title.frame.size.width + 5) - 10, 70 * scrole)];
                ageLa.textAlignment = NSTextAlignmentLeft;
                ageLa.textColor = BaseColor;
                ageLa.font = FONT(14);
                if ([dict objectForKey:@"house"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"house"]];
                }
                [backImgView addSubview:ageLa];
            }
            title.numberOfLines = 2;
            [backImgView addSubview:title];
        }
    }
    else if ([type isEqualToString:@"magazine"]) {
        backImgView.image = IMG(@"magazine6.jpg");
        
        for (int i = 0; i < 8; i++) {
            UILabel *title = [[UILabel alloc] init];
            title.textColor = [UIColor whiteColor];
            title.font = FONT(14);
            title.textAlignment = NSTextAlignmentCenter;
            if (i == 0) {
                title.frame = CGRectMake(30 * scrole, 704 * scrole, 194 * scrole, 20);
                title.text = @"年龄";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_age"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_age"]];
                }
                [backImgView addSubview:infoLa];
            }
            else if (i == 1) {
                title.frame = CGRectMake(224 * scrole, 704 * scrole, 194 * scrole, 20);
                title.text = @"身高";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_height"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_height"]];
                }
                [backImgView addSubview:infoLa];
            }
            else if (i == 2) {
                title.frame = CGRectMake(417 * scrole, 704 * scrole, 194 * scrole, 20);
                title.text = @"购房情况";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"house"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"house"]];
                }
                [backImgView addSubview:infoLa];
            }
            else if (i == 3) {
                title.frame = CGRectMake(30 * scrole, 803 * scrole, 194 * scrole, 20);
                title.text = @"婚姻状况";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_marital_status"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_marital_status"]];
                }
                [backImgView addSubview:infoLa];
            }
            else if (i == 4) {
                title.frame = CGRectMake(224 * scrole, 803 * scrole, 194 * scrole, 20);
                title.text = @"居住地";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_area_in"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_area_in"]];
                }
                [backImgView addSubview:infoLa];
            }
            else if (i == 5) {
                title.frame = CGRectMake(417 * scrole, 803 * scrole, 194 * scrole, 20);
                title.text = @"学历";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_school_age"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_school_age"]];
                }
                [backImgView addSubview:infoLa];
            }
            else if (i == 6) {
                title.frame = CGRectMake(30 * scrole, 906 * scrole, 194 * scrole, 20);
                title.text = @"子女情况";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_childs"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_childs"]];
                }
                [backImgView addSubview:infoLa];
            }
            else {
                title.frame = CGRectMake(224 * scrole, 906 * scrole, 194 * scrole, 20);
                title.text = @"月收入";
                
                UILabel *infoLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 50)];
                infoLa.textColor = COLOR(240, 224, 78,1);
                infoLa.textAlignment = NSTextAlignmentCenter;
                infoLa.font = FONT(14);
                if ([dict objectForKey:@"spouse_month_income"]) {
                    infoLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_month_income"]];
                }
                infoLa.numberOfLines = 0;
                [backImgView addSubview:infoLa];
            }
            [backImgView addSubview:title];
        }
    }
    else if ([type isEqualToString:@"purple"]) {
        backImgView.image = IMG(@"purple6.jpg");
        
        for (int i = 0; i < 8; i++) {
            UILabel *title = [[UILabel alloc] init];
            title.backgroundColor = [UIColor clearColor];
            title.font = FONT(14);
            title.textColor = [UIColor whiteColor];
            if (i == 0) {
                title.frame = CGRectMake(10, 324 * scrole, 250 * scrole, 20);
                title.textAlignment = NSTextAlignmentRight;
                title.text = @"年龄";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentRight;
                if ([dict objectForKey:@"spouse_age"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@岁", [dict objectForKey:@"spouse_age"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 1) {
                title.frame = CGRectMake(372 * scrole, 329 * scrole, backWid - 372 * scrole - 10, 20);
                title.textAlignment = NSTextAlignmentLeft;
                title.text = @"身高";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentLeft;
                if ([dict objectForKey:@"spouse_height"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@厘米", [dict objectForKey:@"spouse_height"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 2) {
                title.frame = CGRectMake(10, 451 * scrole, 154 * scrole, 20);
                title.textAlignment = NSTextAlignmentRight;
                title.text = @"婚姻状况";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentRight;
                if ([dict objectForKey:@"spouse_marital_status"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_marital_status"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 3) {
                title.frame = CGRectMake(470 * scrole, 450 * scrole, backWid - 470 * scrole - 10, 20);
                title.textAlignment = NSTextAlignmentLeft;
                title.text = @"居住地";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 50)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentLeft;
                if ([dict objectForKey:@"spouse_area_in"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_area_in"]];
                }
                ageLa.numberOfLines = 0;
                [backImgView addSubview:ageLa];
            }
            else if (i == 4) {
                title.frame = CGRectMake(10, 606 * scrole, 131 * scrole, 20);
                title.textAlignment = NSTextAlignmentRight;
                title.text = @"子女情况";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentRight;
                if ([dict objectForKey:@"spouse_childs"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_childs"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 5) {
                title.frame = CGRectMake(487 * scrole, 607 * scrole, backWid - 487 * scrole - 10, 20);
                title.textAlignment = NSTextAlignmentLeft;
                title.text = @"学历";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentLeft;
                if ([dict objectForKey:@"spouse_school_age"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_school_age"]];
                }
                [backImgView addSubview:ageLa];
            }
            else if (i == 6) {
                title.frame = CGRectMake(10, 772 * scrole, 255 * scrole, 20);
                title.textAlignment = NSTextAlignmentRight;
                title.text = @"月收入";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentRight;
                if ([dict objectForKey:@"spouse_month_income"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"spouse_month_income"]];
                }
                [backImgView addSubview:ageLa];
            }
            else {
                title.frame = CGRectMake(364 * scrole, 774 * scrole, backWid - 364 * scrole - 10, 20);
                title.textAlignment = NSTextAlignmentLeft;
                title.text = @"购房情况";
                
                UILabel *ageLa = [[UILabel alloc] initWithFrame:CGRectMake(title.frame.origin.x, title.frame.origin.y + title.frame.size.height, title.frame.size.width, 20)];
                ageLa.font = FONT(15);
                ageLa.textColor = COLOR(243, 230, 130,1);
                ageLa.textAlignment = NSTextAlignmentLeft;
                if ([dict objectForKey:@"house"]) {
                    ageLa.text = [NSString stringWithFormat:@"%@", [dict objectForKey:@"house"]];
                }
                [backImgView addSubview:ageLa];
            }
            [backImgView addSubview:title];
        }
    }
    
    return backImgView;
}

- (UIImageView *)imageViewSeven:(CGRect)rect withType:(NSString *)type
{
    UIImageView *backImgView = [[UIImageView alloc] initWithFrame:rect];
    
    if ([type isEqualToString:@"beautiful"]) {
        backImgView.image = IMG(@"beautiful7.jpg");
    }
    else if ([type isEqualToString:@"magazine"]) {
        backImgView.image = IMG(@"magazine7.jpg");
    }
    else if ([type isEqualToString:@"purple"]) {
        backImgView.image = IMG(@"purple7.jpg");
    }
    
    return backImgView;
}

// 判断登录状态
//- (BOOL)isLogin
//{
//    AccountManager *manager = [AccountManager sharedManager];
//    if (manager.key == nil) {
//        return NO;
//    }
//    else {
//        return YES;
//    }
//}

// 登录或取消登录
- (void)loginOrCancel
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"您还没有登录，请先登录" preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"去登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
//        LoginViewController *login = [[LoginViewController alloc] init];
//        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
//        [nav.navigationBar setBackgroundImage:[self createImageWithColor:BaseColor] forBarMetrics:UIBarMetricsDefault];
//        AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//        [delegate.window.rootViewController presentViewController:nav animated:YES completion:^{
//            
//        }];
        
    }]];
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate.window.rootViewController presentViewController:alertController animated:YES completion:^{
        
    }];
}

// 价格显示小数点
- (NSString *)removeFloatAllZero:(NSString *)string
{
    NSString *testNumber = string;
    NSString *outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
    return outNumber;
}

// 两个时间的差
- (NSMutableAttributedString *)remainingTimeMethodAction:(long long)endTime
{
    //得到当前时间
    NSDate *nowData = [NSDate date];
    NSDate *endData = [NSDate dateWithTimeIntervalSince1970:endTime];
    NSCalendar *chineseClendar = [[NSCalendar alloc ] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSUInteger unitFlags =
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear;
    NSDateComponents *cps = [chineseClendar components:unitFlags fromDate:nowData toDate: endData options:0];
    NSInteger Hour = [cps hour];
    NSInteger Min = [cps minute];
    NSInteger Sec = [cps second];
    NSInteger Day = [cps day];
    NSInteger Mon = [cps month];
    NSInteger Year = [cps year];

    NSMutableAttributedString *attStr;
    
    if (Year > 0) {
        NSString *countdown = [NSString stringWithFormat:@"距抢购结束还有%zi年%zi月%zi天%zi小时%zi分%zi秒 ", Year, Mon, Day, Hour, Min, Sec];
        attStr = [[NSMutableAttributedString alloc] initWithString:countdown];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(7, [self timeLength:Year])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Year] + 2, [self timeLength:Mon])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Year] + 1 + [self timeLength:Mon] + 2, [self timeLength:Day])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Year] + 1 + [self timeLength:Mon] + 1 + [self timeLength:Day] + 2, [self timeLength:Hour])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Year] + 1 + [self timeLength:Mon] + 1 + [self timeLength:Day] + 1 + [self timeLength:Hour] + 3, [self timeLength:Min])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Year] + 1 + [self timeLength:Mon] + 1 + [self timeLength:Day] + 1 + [self timeLength:Hour] + 2 + [self timeLength:Min] + 2, [self timeLength:Sec])];
    }
    else if (Year == 0 && Mon > 0) {
        NSString *countdown = [NSString stringWithFormat:@"距抢购结束还有%zi月%zi天%zi小时%zi分%zi秒 ", Mon, Day, Hour, Min, Sec];
        attStr = [[NSMutableAttributedString alloc] initWithString:countdown];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(7, [self timeLength:Mon])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Mon] + 2, [self timeLength:Day])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Mon] + 1 + [self timeLength:Day] + 2, [self timeLength:Hour])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Mon] + 1 + [self timeLength:Day] + 1 + [self timeLength:Hour] + 3, [self timeLength:Min])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Mon] + 1 + [self timeLength:Day] + 1 + [self timeLength:Hour] + 2 + [self timeLength:Min] + 2, [self timeLength:Sec])];
    }
    else if (Year + Mon == 0 && Day > 0) {
        NSString *countdown = [NSString stringWithFormat:@"距抢购结束还有%zi天%zi小时%zi分%zi秒 ", Day, Hour, Min, Sec];
        attStr = [[NSMutableAttributedString alloc] initWithString:countdown];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(7, [self timeLength:Day])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Day] + 2, [self timeLength:Hour])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Day] + 1 + [self timeLength:Hour] + 3, [self timeLength:Min])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Day] + 1 + [self timeLength:Hour] + 2 + [self timeLength:Min] + 2, [self timeLength:Sec])];
    }
    else if (Year + Mon + Day == 0 && Hour > 0) {
        NSString *countdown = [NSString stringWithFormat:@"距抢购结束还有%zi小时%zi分%zi秒 ", Hour, Min, Sec];
        attStr = [[NSMutableAttributedString alloc] initWithString:countdown];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(7, [self timeLength:Hour])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Hour] + 3, [self timeLength:Min])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Hour] + 3 + [self timeLength:Min] + 2, [self timeLength:Sec])];
    }
    else if (Year + Mon + Day + Hour == 0 && Min > 0) {
        NSString *countdown = [NSString stringWithFormat:@"距抢购结束还有%zi分%zi秒", Min, Sec];
        attStr = [[NSMutableAttributedString alloc] initWithString:countdown];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(7, [self timeLength:Min])];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(6 + [self timeLength:Min] + 2, [self timeLength:Sec])];
    }
    else if (Year + Mon + Day + Hour + Min == 0 && Sec > 0) {
        NSString *countdown = [NSString stringWithFormat:@"距抢购结束还有%zi秒", Sec];
        attStr = [[NSMutableAttributedString alloc] initWithString:countdown];
        [attStr addAttribute:NSForegroundColorAttributeName value:BaseColor range:NSMakeRange(7, [self timeLength:Sec])];
    }
    else {
        NSString *countdown= [NSString stringWithFormat:@"活动结束/开始抢购"];
        attStr = [[NSMutableAttributedString alloc] initWithString:countdown];
    }

    return attStr;
}

- (NSInteger)timeLength:(NSUInteger)time
{
    NSString *timeStr = [NSString stringWithFormat:@"%lu", (unsigned long)time];
    return [timeStr length];
}

@end


#pragma mark -
#pragma mark UIViewController(background)

@implementation UIViewController(background)
//修改导航栏颜色。
-(void)addAavigationView:(NSString*)atitle aback:(NSString*)aback
{
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    [title setBackgroundColor:[UIColor clearColor]];
    [title setTextAlignment:NSTextAlignmentCenter];
    title.textColor = [UIColor whiteColor];
    title.font = FONT(20);
    title.text = atitle;
    [title sizeToFit];
    self.navigationItem.titleView = title;
    
    CGRect rect = title.frame;
    title.frame = CGRectMake((kScreanWidth - rect.size.width)/2, (44 - rect.size.height)/2, rect.size.width, rect.size.height);
    
    if (aback)
    {
        UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[IMG(aback) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemBack)];
        
        UIBarButtonItem *nagetion = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        nagetion.width = -10;
        self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:nagetion, leftItem, nil];
    }
}
-(void)leftBarButtonItemBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
